<template>
  <div class="app-container" style="padding: 5px 0 0 0">
    <el-form class="formList" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
             label-width="80px">
      <el-row>
        <!-- <el-col :span="6"> -->
          <el-form-item label="供应商" prop="supplierUid">
            <el-select
              v-model="queryParams.supplierUid"
              placeholder="请选择供应商"
              clearable
              size="small"
              style="width: 232px"
            >
              <el-option
                v-for="dict in supplierUidOptions"
                :key="dict.supplierUid"
                :label="dict.supplierName"
                :value="dict.supplierUid"
              />
            </el-select>
          </el-form-item>
        <!-- </el-col> -->

        <!-- <el-col :span="8"> -->
          <el-form-item label="审核时间" prop="auditTimeArray">
            <el-date-picker
              v-model="queryParams.auditTimeArray"
              type="daterange"
              align="right"
              value-format="yyyy-MM-dd"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 232px"
              :picker-options="pickerOptions">
            </el-date-picker>
          </el-form-item>

          <el-form-item label="申请时间" prop="applyAuthTimeArray">
            <el-date-picker
              v-model="queryParams.applyAuthTimeArray"
              type="daterange"
              align="right"
              value-format="yyyy-MM-dd"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 232px"
              :picker-options="pickerOptions">
            </el-date-picker>
          </el-form-item>
        <!-- </el-col>
        <el-col :span="4"> -->
          
        <!-- </el-col> -->
      </el-row>
      <el-row>
        <!-- <el-col :span="6"> -->
          <el-form-item label="结算编号" prop="settlementNo">
            <el-input
              v-model="queryParams.settlementNo"
              placeholder="请输入结算编号"
              clearable
              size="small"
              style="width: 232px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        <!-- </el-col> -->
          <el-form-item style="margin-left: 10px;">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        <!-- <el-col :span="8"> -->
          
        <!-- </el-col> -->
      </el-row>
    </el-form>

    <div class="divTable" style="margin-top: 10px">
      <el-table v-loading="loading" :data="settlementList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="供应商名称" min-width="120" align="center" prop="supplierName" :show-overflow-tooltip="true"/>
        <el-table-column label="结算编号" align="center" prop="settlementNo" :show-overflow-tooltip="true"/>
        <el-table-column label="订单总额（元）" width="120" align="center" prop="settlementMoneySum" :show-overflow-tooltip="true"/>
        <el-table-column label="申请金额（元）" width="120" align="center" prop="settlementMoney" :show-overflow-tooltip="true"/>
        <el-table-column label="结算金额（元）" width="120" align="center" prop="settlementMoney" :show-overflow-tooltip="true"/>
        <el-table-column label="订单数量" align="center" prop="orderNumber" :show-overflow-tooltip="true"/>
        <el-table-column label="商品数量" align="center" prop="productNumber" :show-overflow-tooltip="true"/>
        <el-table-column label="申请时间" align="center" prop="applyAuthTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.applyAuthTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核状态" align="center" prop="auditStatus" :formatter="auditStatusFormat"/>
        <el-table-column label="付款状态" align="center" prop="payStatus" :formatter="payStatusFormat"/>
        <el-table-column label="付款时间" align="center" prop="payTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="确认收款状态" width="120" align="center" prop="receiveStatus" :formatter="receiveStatusFormat"/>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-zoom-in"
              @click="handleShowDetail(scope.row)"
              v-hasPermi="['supplier:settlement:query']"
            >查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <!--  订单信息对话框  -->
    <el-dialog
      :title="title"
      :visible.sync="auditViewOpenData"
      :modal="true"
      width="1300px"
      append-to-body
    >
      <auditShowData :auditSettlementIdStr.sync=settlementId :key="settlementId"></auditShowData>
      <span slot="footer" class="dialog-footer">
             <el-button type="primary" size="mini" @click="handCloseDetail">确 定</el-button>
          </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listSettlement,
  } from '@/api/supplier/settlement'

  import {
    getSupplierList,
  } from '@/api/supplier/info'
  import auditShowData from '@/views/supplier/settlementAudit/auditShowData';

  export default {
    name: 'Settlement',
    components: {auditShowData},
    data() {
      return {
        //结算ID
        settlementId: null,
        //详细弹出开关
        auditViewOpenData: false,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }]
        },
        //供应商列表
        supplierUidOptions: [],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单结算表格数据
        settlementList: [],
        // 弹出层标题
        title: '',
        //查看详细标题
        viewTitle: '',
        // 是否显示弹出层
        open: false,
        //是否显示查看详细弹出层
        viewOpen: false,
        //查看详细数据
        showData: [],
        // 审核状态字典
        auditStatusOptions: [],
        // 付款状态字典
        payStatusOptions: [],
        // 确认收款状态字典
        receiveStatusOptions: [],
        //供应商列表
        supplierUidOptions: [],
        // 查询参数
        queryParams: {
          supplierUid: null,
          payTimeArray: null,
          receiveTimeArray: null,
          auditTimeArray: null,
          createTimeArray: null,
          pageNum: 1,
          pageSize: 10,
          settlementNo: null,
          createTime: null,
          auditStatus: -1,
          payStatus: null,
          payTime: null,
          receiveStatus: null,
          receiveTime: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      }
    },
    created() {
      this.getList()

      getSupplierList().then((response) => {
        this.supplierUidOptions = response.data
      })
      this.getDicts('supplier_audit_state').then(response => {
        this.auditStatusOptions = response.data
      })
      this.getDicts('supplier_pay_state').then(response => {
        this.payStatusOptions = response.data
      })
      this.getDicts('supplier_receive_state').then(response => {
        this.receiveStatusOptions = response.data
      })
    },
    methods: {
      /** 查询订单结算列表 */
      getList() {
        this.loading = true
        listSettlement(this.queryParams).then(response => {
          this.settlementList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 审核状态字典翻译
      auditStatusFormat(row, column) {
        return this.selectDictLabel(this.auditStatusOptions, row.auditStatus)
      },
      // 付款状态字典翻译
      payStatusFormat(row, column) {
        return this.selectDictLabel(this.payStatusOptions, row.payStatus)
      },
      // 确认收款状态字典翻译
      receiveStatusFormat(row, column) {
        return this.selectDictLabel(this.receiveStatusOptions, row.receiveStatus)
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          settlementId: null,
          platformUid: null,
          supplierUid: null,
          settlementNo: null,
          settlementMoney: null,
          paymentMoney: null,
          orderNumber: null,
          productNumber: null,
          dataStatus: '0',
          createTime: null,
          createUser: null,
          updateTime: null,
          updateUser: null,
          auditStatus: '0',
          auditUser: null,
          auditTime: null,
          auditMsg: null,
          payStatus: null,
          payTime: null,
          payUser: null,
          receiveStatus: null,
          receiveTime: null,
          receiveUser: null
        }
        this.resetForm('form')
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm('queryForm')
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.settlementId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 查看详情按钮操作 **/
      handleShowDetail(row) {
        this.settlementId = row.settlementId
        this.auditViewOpenData = true
      },
      handCloseDetail() {
        this.auditViewOpenData = false
        this.viewOpen = false
        this.showData = []
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('supplier/settlement/export', {
          ...this.queryParams
        }, `supplier_settlement.xlsx`)
      }
    }
  }
</script>
